package com.yytek.am.mqtt;

import com.yytek.am.service.impl.AmRuleHandleServiceImpl;
import com.yytek.common.client.base.MqMessage;
import com.yytek.common.client.net.IotMqttClient;
import com.yytek.common.client.net.IotMqttContext;
import com.yytek.common.client.net.MqttCallback;
import com.yytek.common.core.constant.MqttConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 告警源数据处理mqtt
 */
@Service
@Slf4j
public class AmMqttService implements MqttCallback {

    @Resource
    IotMqttClient iotMqttClient;
    @Resource
    private AmRuleHandleServiceImpl amRuleHandleService;

    @PostConstruct
    public void init() {
        //订阅tddb业务
        iotMqttClient.subscribe(MqttConstants.AM_TOPIC,this);
    }
    @Override
    public void onMessageReceived(IotMqttContext context, MqMessage msg) {
        //业务处理
        System.out.println("---topic----"+context.getTopic());
        //收取到数据规则处理
        amRuleHandleService.handleAmMqttMsg(msg);
    }


}
